/**
 * Created by sun on 2016/8/4.
 */
define(function (require) {
    var app = require('/../js/app');
    require('ui-table');


    var toastr =require('toastr');

    app.useModule("ui.table");



    var datepicker = require('datepicker');
    app.controller('collect_listCtrl', ['$scope','$http','$filter' ,function ($scope, $http,$filter) {
        $scope.orderParams = {
            url: "/admin/invest/getCollectList"
        };
        datepicker($scope);;
        $scope.ctrlScope=$scope;
        //创建
        $scope.addOrderModal=function(){
            $scope.orderModal = !$scope.orderModal ;
        };
        $scope.getShow=function(parm){
            $http({
                method: 'POST',
                url: "/admin/invest/statCollect",
                data:parm,
            }).success(function(data) {
                console.info(data);
                $scope.show=data;
            }).error(function(data) {});
        }
        $scope.getShow();
        //全局查询
        $scope.search = function() {
            $scope.ctrlScope.itemsearch.collectStartTime=$scope.ctrlScope.itemsearch.collectStartTimex;
            $scope.ctrlScope.itemsearch.collectEendTime=$scope.ctrlScope.itemsearch.collectEendTimex;
            $scope.ctrlScope.itemsearch.addStartTime= $scope.ctrlScope.itemsearch.addStartTimex;
            $scope.ctrlScope.itemsearch.addEndTime= $scope.ctrlScope.itemsearch.addEndTimex;
            $scope.ctrlScope.itemsearch.collectStartTime=$filter('date')($scope.ctrlScope.itemsearch.collectStartTime,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.collectEendTime=$filter('date')($scope.ctrlScope.itemsearch.collectEendTime,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.addStartTime=$filter('date')($scope.ctrlScope.itemsearch.addStartTime,'yyyy-MM-dd');
            $scope.ctrlScope.itemsearch.addEndTime=$filter('date')($scope.ctrlScope.itemsearch.addEndTime,'yyyy-MM-dd');
            //表格查询参数设置
            $scope.orderParams.ajaxParam=$scope.ctrlScope.itemsearch;
            //表格刷新
            $scope.orderParams.reload();
            var parm=$scope.ctrlScope.itemsearch;
            $scope.getShow(parm);
        };
        //全局查询重置
        $scope.reset=function(){
            $scope.orderParams.ajaxParam={};
            $scope.ctrlScope.itemsearch={};
            $scope.orderParams.reload();
            $scope.getShow();
        };
        //导出
        $scope.download=function(){
            var params=$scope.ctrlScope.itemsearch;
            $http.post("/admin/invest/excel/collect",params)
                .success(function (data){
                    console.info(data);
                    if(data.result=="success"){
                        window.open(data.file);
                    }else{
                        toastr.error("导出失败");
                    }
                }).error(function(data){

                });
        };
    }]);
});